/*
 * Copyright (c) 2012 Supin P Surendran <supinps@gmail.com>.
 *
 * This file is part of InventoryMan.
 *
 * InventoryMan is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * InventoryMan is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with licenseTest.  If not, see <http ://www.gnu.org/licenses/>.
 *
 */
package InventoryMan;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.UnsupportedLookAndFeelException;

/**
 *
 * @author supinps
 */
public class MainWindow extends javax.swing.JFrame {

    /** Creates new form MainWindow */
    public MainWindow() {
        try {
            javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
        } catch (UnsupportedLookAndFeelException ex) {
            Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
        }
        //Loading JDBC Driver for Mysql
        try {
            java.lang.Class.forName("org.gjt.mm.mysql.Driver");
        }catch(java.lang.ClassNotFoundException e) {
            javax.swing.JOptionPane.showMessageDialog(null, "Unable to Load JDBC Driver");
            System.exit(0);
        }
        initComponents();
        java.awt.Image icon=null;
        try {
            icon=javax.imageio.ImageIO.read(getClass().getResource("/Resources/icon_small.png"));
        }catch(Exception ex) {ex.printStackTrace();}
        setIconImage(icon);
        mnuSystemLogOut.setVisible(false);
        prefPath=this.getClass().getName();
        prefServer=java.util.prefs.Preferences.userRoot().node(prefPath);
        setServerConfig();

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        desktopPane = new javax.swing.JDesktopPane();
        menuBar = new javax.swing.JMenuBar();
        mnuSystem = new javax.swing.JMenu();
        mnuSystemLogIn = new javax.swing.JMenuItem();
        mnuSystemLogOut = new javax.swing.JMenuItem();
        mnuSystemServer = new javax.swing.JMenuItem();
        mnuSystemQuit = new javax.swing.JMenuItem();
        mnuIndent = new javax.swing.JMenu();
        mnuIndentNew = new javax.swing.JMenuItem();
        mnuIndentView = new javax.swing.JMenuItem();
        mnuIWO = new javax.swing.JMenu();
        mnuIWONew = new javax.swing.JMenuItem();
        mnuIWOView = new javax.swing.JMenuItem();
        mnuLCR = new javax.swing.JMenu();
        mnuLCRNew = new javax.swing.JMenuItem();
        mnuLCRView = new javax.swing.JMenuItem();
        mnuStock = new javax.swing.JMenu();
        mnuStockNew = new javax.swing.JMenuItem();
        mnuStockView = new javax.swing.JMenuItem();
        mnuAdmin = new javax.swing.JMenu();
        smnuItem = new javax.swing.JMenu();
        smnuItemNew = new javax.swing.JMenuItem();
        smnuItemView = new javax.swing.JMenuItem();
        smnuItemModify = new javax.swing.JMenuItem();
        smnuItemRemove = new javax.swing.JMenuItem();
        smnuCustomer = new javax.swing.JMenu();
        smnuCustomerNew = new javax.swing.JMenuItem();
        smnuCustomerView = new javax.swing.JMenuItem();
        smnuCustomerModify = new javax.swing.JMenuItem();
        smnuCustomerRemove = new javax.swing.JMenuItem();
        smnuVendor = new javax.swing.JMenu();
        smnuVendorNew = new javax.swing.JMenuItem();
        smnuVendorView = new javax.swing.JMenuItem();
        smnuVendorModify = new javax.swing.JMenuItem();
        smnuVendorRemove = new javax.swing.JMenuItem();
        mnuHelp = new javax.swing.JMenu();
        mnuHelpAbout = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("InventoryMan");
        setExtendedState(javax.swing.JFrame.MAXIMIZED_BOTH);
        setName("Form"); // NOI18N

        desktopPane.setName("desktopPane"); // NOI18N

        menuBar.setName("menuBar"); // NOI18N

        mnuSystem.setText("System");
        mnuSystem.setName("mnuSystem"); // NOI18N

        mnuSystemLogIn.setText("Log In");
        mnuSystemLogIn.setName("mnuSystemLogIn"); // NOI18N
        mnuSystemLogIn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuSystemLogInActionPerformed(evt);
            }
        });
        mnuSystem.add(mnuSystemLogIn);

        mnuSystemLogOut.setText("Log Out");
        mnuSystemLogOut.setName("mnuSystemLogOut"); // NOI18N
        mnuSystemLogOut.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuSystemLogOutActionPerformed(evt);
            }
        });
        mnuSystem.add(mnuSystemLogOut);

        mnuSystemServer.setText("Server");
        mnuSystemServer.setName("mnuSystemServer"); // NOI18N
        mnuSystemServer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuSystemServerActionPerformed(evt);
            }
        });
        mnuSystem.add(mnuSystemServer);

        mnuSystemQuit.setText("Quit");
        mnuSystemQuit.setName("mnuSystemQuit"); // NOI18N
        mnuSystemQuit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuSystemQuitActionPerformed(evt);
            }
        });
        mnuSystem.add(mnuSystemQuit);

        menuBar.add(mnuSystem);

        mnuIndent.setText("Indent");
        mnuIndent.setEnabled(false);
        mnuIndent.setName("mnuIndent"); // NOI18N

        mnuIndentNew.setText("New Entry");
        mnuIndentNew.setEnabled(false);
        mnuIndentNew.setName("mnuIndentNew"); // NOI18N
        mnuIndentNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuIndentNewActionPerformed(evt);
            }
        });
        mnuIndent.add(mnuIndentNew);

        mnuIndentView.setText("View Entry");
        mnuIndentView.setName("mnuIndentView"); // NOI18N
        mnuIndentView.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuIndentViewActionPerformed(evt);
            }
        });
        mnuIndent.add(mnuIndentView);

        menuBar.add(mnuIndent);

        mnuIWO.setText("IWO");
        mnuIWO.setEnabled(false);
        mnuIWO.setName("mnuIWO"); // NOI18N

        mnuIWONew.setText("New Entry");
        mnuIWONew.setEnabled(false);
        mnuIWONew.setName("mnuIWONew"); // NOI18N
        mnuIWONew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuIWONewActionPerformed(evt);
            }
        });
        mnuIWO.add(mnuIWONew);

        mnuIWOView.setText("View Entry");
        mnuIWOView.setName("mnuIWOView"); // NOI18N
        mnuIWOView.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuIWOViewActionPerformed(evt);
            }
        });
        mnuIWO.add(mnuIWOView);

        menuBar.add(mnuIWO);

        mnuLCR.setText("LCR");
        mnuLCR.setEnabled(false);
        mnuLCR.setName("mnuLCR"); // NOI18N

        mnuLCRNew.setText("New Entry");
        mnuLCRNew.setEnabled(false);
        mnuLCRNew.setName("mnuLCRNew"); // NOI18N
        mnuLCRNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuLCRNewActionPerformed(evt);
            }
        });
        mnuLCR.add(mnuLCRNew);

        mnuLCRView.setText("View Entry");
        mnuLCRView.setName("mnuLCRView"); // NOI18N
        mnuLCRView.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuLCRViewActionPerformed(evt);
            }
        });
        mnuLCR.add(mnuLCRView);

        menuBar.add(mnuLCR);

        mnuStock.setText("Stock");
        mnuStock.setEnabled(false);
        mnuStock.setName("mnuStock"); // NOI18N

        mnuStockNew.setText("New Entry");
        mnuStockNew.setEnabled(false);
        mnuStockNew.setName("mnuStockNew"); // NOI18N
        mnuStockNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuStockNewActionPerformed(evt);
            }
        });
        mnuStock.add(mnuStockNew);

        mnuStockView.setText("View");
        mnuStockView.setName("mnuStockView"); // NOI18N
        mnuStockView.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuStockViewActionPerformed(evt);
            }
        });
        mnuStock.add(mnuStockView);

        menuBar.add(mnuStock);

        mnuAdmin.setText("Admin");
        mnuAdmin.setEnabled(false);
        mnuAdmin.setName("mnuAdmin"); // NOI18N

        smnuItem.setText("Item");
        smnuItem.setName("smnuItem"); // NOI18N

        smnuItemNew.setText("New Entry");
        smnuItemNew.setEnabled(false);
        smnuItemNew.setName("smnuItemNew"); // NOI18N
        smnuItemNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                smnuItemNewActionPerformed(evt);
            }
        });
        smnuItem.add(smnuItemNew);

        smnuItemView.setText("View Entry");
        smnuItemView.setName("smnuItemView"); // NOI18N
        smnuItemView.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                smnuItemViewActionPerformed(evt);
            }
        });
        smnuItem.add(smnuItemView);

        smnuItemModify.setText("Modify");
        smnuItemModify.setEnabled(false);
        smnuItemModify.setName("smnuItemModify"); // NOI18N
        smnuItemModify.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                smnuItemModifyActionPerformed(evt);
            }
        });
        smnuItem.add(smnuItemModify);

        smnuItemRemove.setText("Remove");
        smnuItemRemove.setEnabled(false);
        smnuItemRemove.setName("smnuItemRemove"); // NOI18N
        smnuItemRemove.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                smnuItemRemoveActionPerformed(evt);
            }
        });
        smnuItem.add(smnuItemRemove);

        mnuAdmin.add(smnuItem);

        smnuCustomer.setText("Customer");
        smnuCustomer.setName("smnuCustomer"); // NOI18N

        smnuCustomerNew.setText("New Entry");
        smnuCustomerNew.setEnabled(false);
        smnuCustomerNew.setName("smnuCustomerNew"); // NOI18N
        smnuCustomerNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                smnuCustomerNewActionPerformed(evt);
            }
        });
        smnuCustomer.add(smnuCustomerNew);

        smnuCustomerView.setText("View Entry");
        smnuCustomerView.setName("smnuCustomerView"); // NOI18N
        smnuCustomerView.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                smnuCustomerViewActionPerformed(evt);
            }
        });
        smnuCustomer.add(smnuCustomerView);

        smnuCustomerModify.setText("Modify");
        smnuCustomerModify.setEnabled(false);
        smnuCustomerModify.setName("smnuCustomerModify"); // NOI18N
        smnuCustomerModify.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                smnuCustomerModifyActionPerformed(evt);
            }
        });
        smnuCustomer.add(smnuCustomerModify);

        smnuCustomerRemove.setText("Remove");
        smnuCustomerRemove.setEnabled(false);
        smnuCustomerRemove.setName("smnuCustomerRemove"); // NOI18N
        smnuCustomerRemove.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                smnuCustomerRemoveActionPerformed(evt);
            }
        });
        smnuCustomer.add(smnuCustomerRemove);

        mnuAdmin.add(smnuCustomer);

        smnuVendor.setText("Vendor");
        smnuVendor.setName("smnuVendor"); // NOI18N

        smnuVendorNew.setText("New Entry");
        smnuVendorNew.setEnabled(false);
        smnuVendorNew.setName("smnuVendorNew"); // NOI18N
        smnuVendorNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                smnuVendorNewActionPerformed(evt);
            }
        });
        smnuVendor.add(smnuVendorNew);

        smnuVendorView.setText("View Entry");
        smnuVendorView.setName("smnuVendorView"); // NOI18N
        smnuVendorView.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                smnuVendorViewActionPerformed(evt);
            }
        });
        smnuVendor.add(smnuVendorView);

        smnuVendorModify.setText("Modify");
        smnuVendorModify.setEnabled(false);
        smnuVendorModify.setName("smnuVendorModify"); // NOI18N
        smnuVendorModify.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                smnuVendorModifyActionPerformed(evt);
            }
        });
        smnuVendor.add(smnuVendorModify);

        smnuVendorRemove.setText("Remove");
        smnuVendorRemove.setEnabled(false);
        smnuVendorRemove.setName("smnuVendorRemove"); // NOI18N
        smnuVendorRemove.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                smnuVendorRemoveActionPerformed(evt);
            }
        });
        smnuVendor.add(smnuVendorRemove);

        mnuAdmin.add(smnuVendor);

        menuBar.add(mnuAdmin);

        mnuHelp.setText("Help");
        mnuHelp.setName("mnuHelp"); // NOI18N

        mnuHelpAbout.setText("About");
        mnuHelpAbout.setName("mnuHelpAbout"); // NOI18N
        mnuHelpAbout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuHelpAboutActionPerformed(evt);
            }
        });
        mnuHelp.add(mnuHelpAbout);

        menuBar.add(mnuHelp);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 279, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void mnuSystemLogInActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuSystemLogInActionPerformed
        setServerConfig();
        LoginDialogfrm=new LoginDialog(this,serverURL);
        desktopPane.add(LoginDialogfrm);
        LoginDialogfrm.setVisible(true);
    }//GEN-LAST:event_mnuSystemLogInActionPerformed

    private void mnuSystemQuitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuSystemQuitActionPerformed
        System.exit(0);
    }//GEN-LAST:event_mnuSystemQuitActionPerformed

    private void mnuSystemServerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuSystemServerActionPerformed
        initServerConfig();
    }//GEN-LAST:event_mnuSystemServerActionPerformed

    private void smnuItemNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_smnuItemNewActionPerformed
        newItem=new ItemNew(imConnection);
        desktopPane.add(newItem);
        newItem.setVisible(true);
    }//GEN-LAST:event_smnuItemNewActionPerformed

    private void smnuItemModifyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_smnuItemModifyActionPerformed
        modifyItem=new ItemModify(imConnection);
        desktopPane.add(modifyItem);
        modifyItem.setVisible(true);
    }//GEN-LAST:event_smnuItemModifyActionPerformed

    private void smnuItemRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_smnuItemRemoveActionPerformed
        remItem=new ItemRemove(imConnection);
        desktopPane.add(remItem);
        remItem.setVisible(true);
    }//GEN-LAST:event_smnuItemRemoveActionPerformed

    private void smnuItemViewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_smnuItemViewActionPerformed
        viewItem=new ItemView(imConnection);
        desktopPane.add(viewItem);
        viewItem.setVisible(true);
    }//GEN-LAST:event_smnuItemViewActionPerformed

    private void smnuCustomerNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_smnuCustomerNewActionPerformed
        newCust=new CustNew(imConnection);
        desktopPane.add(newCust);
        newCust.setVisible(true);
    }//GEN-LAST:event_smnuCustomerNewActionPerformed

    private void smnuCustomerModifyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_smnuCustomerModifyActionPerformed
        modifyCust=new CustModify(imConnection);
        desktopPane.add(modifyCust);
        modifyCust.setVisible(true);
    }//GEN-LAST:event_smnuCustomerModifyActionPerformed

    private void smnuCustomerRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_smnuCustomerRemoveActionPerformed
        remCust=new CustRemove(imConnection);
        desktopPane.add(remCust);
        remCust.setVisible(true);
    }//GEN-LAST:event_smnuCustomerRemoveActionPerformed

    private void smnuCustomerViewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_smnuCustomerViewActionPerformed
        viewCust=new CustView(imConnection);
        desktopPane.add(viewCust);
        viewCust.setVisible(true);
    }//GEN-LAST:event_smnuCustomerViewActionPerformed

    private void smnuVendorNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_smnuVendorNewActionPerformed
        newVendor=new VendorNew(imConnection);
        desktopPane.add(newVendor);
        newVendor.setVisible(true);
    }//GEN-LAST:event_smnuVendorNewActionPerformed

    private void smnuVendorViewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_smnuVendorViewActionPerformed
        viewVendor=new VendorView(imConnection);
        desktopPane.add(viewVendor);
        viewVendor.setVisible(true);
    }//GEN-LAST:event_smnuVendorViewActionPerformed

    private void smnuVendorModifyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_smnuVendorModifyActionPerformed
        modifyVendor=new VendorModify(imConnection);
        desktopPane.add(modifyVendor);
        modifyVendor.setVisible(true);
    }//GEN-LAST:event_smnuVendorModifyActionPerformed

    private void smnuVendorRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_smnuVendorRemoveActionPerformed
        remVendor=new VendorRemove(imConnection);
        desktopPane.add(remVendor);
        remVendor.setVisible(true);
    }//GEN-LAST:event_smnuVendorRemoveActionPerformed

    private void mnuIndentNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuIndentNewActionPerformed
        newIndent=new IndentNew(imConnection);
        desktopPane.add(newIndent);
        newIndent.setVisible(true);
    }//GEN-LAST:event_mnuIndentNewActionPerformed

    private void mnuIndentViewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuIndentViewActionPerformed
        viewIndent=new IndentView(imConnection);
        desktopPane.add(viewIndent);
        viewIndent.setVisible(true);
    }//GEN-LAST:event_mnuIndentViewActionPerformed

    private void mnuIWONewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuIWONewActionPerformed
        newIwo=new IwoNew(imConnection);
        desktopPane.add(newIwo);
        newIwo.setVisible(true);
    }//GEN-LAST:event_mnuIWONewActionPerformed

    private void mnuIWOViewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuIWOViewActionPerformed
        viewIwo=new IwoView(imConnection);
        desktopPane.add(viewIwo);
        viewIwo.setVisible(true);
    }//GEN-LAST:event_mnuIWOViewActionPerformed

    private void mnuLCRNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuLCRNewActionPerformed
        newLcr=new LcrNew(imConnection);
        desktopPane.add(newLcr);
        newLcr.setVisible(true);
    }//GEN-LAST:event_mnuLCRNewActionPerformed

    private void mnuLCRViewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuLCRViewActionPerformed
        viewLcr=new LcrView(imConnection);
        desktopPane.add(viewLcr);
        viewLcr.setVisible(true);
    }//GEN-LAST:event_mnuLCRViewActionPerformed

    private void mnuStockNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuStockNewActionPerformed
        newStock=new StockNew(imConnection);
        desktopPane.add(newStock);
        newStock.setVisible(true);
    }//GEN-LAST:event_mnuStockNewActionPerformed

    private void mnuStockViewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuStockViewActionPerformed
        viewStock=new StockView(imConnection);
        desktopPane.add(viewStock);
        viewStock.setVisible(true);
    }//GEN-LAST:event_mnuStockViewActionPerformed

    private void mnuHelpAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuHelpAboutActionPerformed
        About abt=new About();
        desktopPane.add(abt);
        abt.setVisible(true);
    }//GEN-LAST:event_mnuHelpAboutActionPerformed

    private void mnuSystemLogOutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuSystemLogOutActionPerformed
        try {
            imConnection.close();
            mnuIndent.setEnabled(false);
            mnuIWO.setEnabled(false);
            mnuLCR.setEnabled(false);
            mnuStock.setEnabled(false);
            mnuAdmin.setEnabled(false);
            mnuSystemLogOut.setVisible(false);
            mnuSystemLogIn.setVisible(true);
        }
        catch(java.sql.SQLException ex) {
            javax.swing.JOptionPane.showMessageDialog(this, ex.toString());
        }
    }//GEN-LAST:event_mnuSystemLogOutActionPerformed

    //user defined method definitions
    public void initServerConfig() {
        try {
        ServerConfig serverConfigDialog=new ServerConfig(prefServer);
        desktopPane.add(serverConfigDialog);
        serverConfigDialog.setVisible(true);
        }catch(Exception e) {
            javax.swing.JOptionPane.showMessageDialog(null, e.toString());
        }
    }
    public void setServerConfig() {
        System.out.println(prefServer.get("ip", ""));
        if(prefServer.get("ip", "").isEmpty()) {
            initServerConfig();
        }
        String ip=prefServer.get("ip", "127.0.0.1");
        String port=prefServer.get("port", "3306");
        serverURL="jdbc:mysql://"+ip+":"+port;
        System.out.println(serverURL);
    }
    public void initMain(java.sql.Connection conn,int i) {
        imConnection=conn;
        designationId=i;
        mnuSystemLogIn.setVisible(false);
        mnuSystemLogOut.setVisible(true);
        mnuIndent.setEnabled(true);
        mnuIWO.setEnabled(true);
        mnuLCR.setEnabled(true);
        mnuStock.setEnabled(true);
        mnuAdmin.setEnabled(true);
        switch(designationId){
            case 101:
                mnuIndentNew.setEnabled(true);
                mnuIWONew.setEnabled(true);
                mnuLCRNew.setEnabled(true);
                mnuStockNew.setEnabled(true);
                smnuItemNew.setEnabled(true);
                smnuItemModify.setEnabled(true);
                smnuItemRemove.setEnabled(true);
                smnuCustomerNew.setEnabled(true);
                smnuCustomerModify.setEnabled(true);
                smnuCustomerRemove.setEnabled(true);
                smnuVendorNew.setEnabled(true);
                smnuVendorModify.setEnabled(true);
                smnuVendorRemove.setEnabled(true);
                break;
            case 102:
                mnuIndentNew.setEnabled(true);
                mnuStockNew.setEnabled(true);
                break;
            case 103:
                mnuIWONew.setEnabled(true);
                mnuLCRNew.setEnabled(true);
                break;
        }
    }
    //End of method definitions
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainWindow().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDesktopPane desktopPane;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenu mnuAdmin;
    private javax.swing.JMenu mnuHelp;
    private javax.swing.JMenuItem mnuHelpAbout;
    private javax.swing.JMenu mnuIWO;
    private javax.swing.JMenuItem mnuIWONew;
    private javax.swing.JMenuItem mnuIWOView;
    private javax.swing.JMenu mnuIndent;
    private javax.swing.JMenuItem mnuIndentNew;
    private javax.swing.JMenuItem mnuIndentView;
    private javax.swing.JMenu mnuLCR;
    private javax.swing.JMenuItem mnuLCRNew;
    private javax.swing.JMenuItem mnuLCRView;
    private javax.swing.JMenu mnuStock;
    private javax.swing.JMenuItem mnuStockNew;
    private javax.swing.JMenuItem mnuStockView;
    private javax.swing.JMenu mnuSystem;
    private javax.swing.JMenuItem mnuSystemLogIn;
    private javax.swing.JMenuItem mnuSystemLogOut;
    private javax.swing.JMenuItem mnuSystemQuit;
    private javax.swing.JMenuItem mnuSystemServer;
    private javax.swing.JMenu smnuCustomer;
    private javax.swing.JMenuItem smnuCustomerModify;
    private javax.swing.JMenuItem smnuCustomerNew;
    private javax.swing.JMenuItem smnuCustomerRemove;
    private javax.swing.JMenuItem smnuCustomerView;
    private javax.swing.JMenu smnuItem;
    private javax.swing.JMenuItem smnuItemModify;
    private javax.swing.JMenuItem smnuItemNew;
    private javax.swing.JMenuItem smnuItemRemove;
    private javax.swing.JMenuItem smnuItemView;
    private javax.swing.JMenu smnuVendor;
    private javax.swing.JMenuItem smnuVendorModify;
    private javax.swing.JMenuItem smnuVendorNew;
    private javax.swing.JMenuItem smnuVendorRemove;
    private javax.swing.JMenuItem smnuVendorView;
    // End of variables declaration//GEN-END:variables

    //Manually Declared Variables
    private java.sql.Connection imConnection;
    private int designationId;
    private java.util.prefs.Preferences prefServer;
    private String prefPath;
    private String serverURL;
    //End of Declarations
    //Child window Declarations
    LoginDialog LoginDialogfrm;
    //Item
    ItemNew newItem;
    ItemView viewItem;
    ItemModify modifyItem;
    ItemRemove remItem;
    ///////////////////
    //Customer
    CustNew newCust;
    CustModify modifyCust;
    CustRemove remCust;
    CustView viewCust;
    //Vendor
    VendorNew newVendor;
    VendorModify modifyVendor;
    VendorRemove remVendor;
    VendorView viewVendor;
    //Indent
    IndentNew newIndent;
    IndentView viewIndent;
    //IWO
    IwoNew newIwo;
    IwoView viewIwo;
    //LCR
    LcrNew newLcr;
    LcrView viewLcr;
    //Stock
    StockNew newStock;
    StockView viewStock;
    //End of Declarations
}